#ifndef JSON_DATA_HPP
#define JSON_DATA_HPP
#include <jsoncpp/json/json.h>
#include <string>
#include <cstring>
#include <iostream>
class JsonData_convert
{
    public:
      JsonData_convert(){}
      ~JsonData_convert(){}
    //example
    double seatx,seaty,seatz;
    double linear_x,linear_y,angular_z; //速度控制用
    int count;
    std::string name;  
    std::string json_msg;
    void receive_msg(std::string &msg);
    void receive_ctl(std::string &msg);
    void set_json_msg(void);
};
void JsonData_convert::receive_ctl(std::string &msg)
{
     Json::Reader reader;
     Json::Value json_val;
     if(reader.parse(msg, json_val))
     {
        linear_x = json_val["linear_x"].asDouble();  //asInt  asString
        linear_y = json_val["linear_y"].asDouble();
        angular_z = json_val["angular_z"].asDouble();
        //name = json_val["name"].asString();
     }
}
void JsonData_convert::receive_msg(std::string &msg)
{
     Json::Reader reader;
     Json::Value json_val;
     if(reader.parse(msg, json_val))
     {
        seatx = json_val["seatx"].asDouble();  //asInt  asString
        seaty = json_val["seaty"].asDouble();
        seatz = json_val["seatz"].asDouble();
        name = json_val["name"].asString();
     }
}
void JsonData_convert::set_json_msg(void)
{
    Json::Value json_val;
        json_val["seatx"] = seatx;
        json_val["seaty"] = seaty;
        json_val["seatz"] = seatz;
        json_val["name"] = name;
        json_msg = json_val.toStyledString();
}

#endif